﻿using System.IO;
using System.Xml.Serialization;

namespace Halk.Config
{
    public class SystemManage
    {
        private static SystemManage _systemManage;

        public static SystemManage Instace()
        {
            return _systemManage ?? (_systemManage = new SystemManage());
        }

        private SystemInfo _sysInfo;

        public SystemInfo SysInfo
        {
            get { return _sysInfo; }
        }

        private static readonly object ObjLock = new object();

        /// <summary>
        /// 初始化配置文件
        /// </summary>
        public void Load()
        {
            lock (ObjLock)
            {
                _sysInfo = new SystemInfo();
                using (FileStream stream = File.Open(@"conf\system.xml", FileMode.Open))
                {
                    var xmlserializer = new XmlSerializer(typeof(SystemInfo));
                    _sysInfo = xmlserializer.Deserialize(stream) as SystemInfo;
                    stream.Close();
                    stream.Dispose();
                }
            }
        }

        public bool GetOnOff()
        {
            if (_sysInfo == null)
                Load();

            return _sysInfo != null && _sysInfo.OnOff.Equals(1);
        }

        public string GetSysType()
        {
            if (_sysInfo == null)
                Load();

            return _sysInfo != null ? _sysInfo.SysType : "";
        }
    }
}
